/**
 * 
 */
package fhq.hcmute.modernshopping.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import fhq.hcmute.modernshopping.ProjectUtil;
import fhq.hcmute.modernshopping.R;
import fhq.hcmute.modernshopping.adapter.Product;

/**
 * @author: Hien Nguyen Le
 * @emai: hien.nguyenle.it@gmail.com
 * 
 */
public class ProductInfo extends Fragment {
	private static ProductInfo instance = null;
	private TextView txt_ProductName;
	private TextView txt_ProductCode;
	private TextView txt_ProductPrice;
	private TextView txt_ProductMadein;
	private Product product;

	private ProductInfo(Product product) {
		this.product = product;
	}

	public static ProductInfo getProductInfo(Product product) {
		if (instance == null) {
			instance = new ProductInfo(product);

		}
		return instance;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View root = inflater.inflate(R.layout.fragment_product_info, container,
				false);
		txt_ProductName = (TextView) root.findViewById(R.id.txt_product_name);
		txt_ProductCode = (TextView) root.findViewById(R.id.txt_product_code);
		txt_ProductPrice = (TextView) root.findViewById(R.id.txt_product_price);
		txt_ProductMadein = (TextView) root
				.findViewById(R.id.txt_product_madein);
		initProduct(product);
		return root;
	}

	private void initProduct(Product product) {
		txt_ProductName.setText(product.getName());
		txt_ProductCode.setText(product.getCode() + "");
		txt_ProductPrice.setText(ProjectUtil.formatCurrency(product.getPrice())
				+ getString(R.string.curency));
		txt_ProductMadein.setText(product.getMadeIn());
	}

	public static void destroyInstance() {
		ProductInfo.instance = null;
	}
}
